<template>
    <div class="component-radio-box">
        <div class="title">{{title}}</div>
        <div class="box-list clear-float">
            <div class="item" v-for="(item, key) in items" :class="{'text-red': value == key || value.indexOf && value.indexOf(key) != -1}">
                <span @click="handleClick(key)">{{item}}</span>
            </div>
        </div>
    </div>
</template>

<style lang="less" scoped>

    @import '../style/variable';

    .component-radio-box{
        padding-left: 1.5rem;
        .title{
            font-size: 1.3rem;
            line-height: 1.9rem;
            margin: 1.2rem 0 .9rem;
            color: @color-text-gray;
        }
        .box-list{
            text-align: center;
            .item{
                width: 25%;
                float: left;
                padding-right: 1.5rem;
                box-sizing: border-box;
                &:nth-child(1n + 5){
                    margin-top: 1.5rem;
                }
                span{
                    display: block;
                    background-color: @color-block-gray;
                    line-height: 3.3rem;
                    border-radius: .2rem;
                }
            }
        }
    }
</style>

<script>
    export default {
        data(){
            return {
                val: this.value
            }
        },
        props: ['title', 'items', 'value'],
        methods: {
            handleClick(key){
                if(this.value.constructor == Array){
                    const k = this.val.indexOf(key);
                    if(k == -1){
                        this.val.push(key)
                    }else{
                        this.val.splice(k, 1);
                    }
                    this.$emit('input', this.val);
                }else{
                    this.$emit('input', key);
                }

            }
        }
    }
</script>